package org.ms.mconf.sdk.service.support;

import lombok.*;
import org.ms.mconf.sdk.model.MetaMultiDataConfig;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The Cache Config
 *
 * @author lry
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class CacheConfig implements Serializable {

    private Map<String, Map<String, MetaMultiDataConfig>> microConfigs = new HashMap<>();

    public CacheConfig(String application, List<MetaMultiDataConfig> metaMultiDataConfigs) {
        Map<String, MetaMultiDataConfig> configs = microConfigs.computeIfAbsent(application, k -> new HashMap<>());
        for (MetaMultiDataConfig metaMultiDataConfig : metaMultiDataConfigs) {
            configs.put(metaMultiDataConfig.getMeta().getConfig(), metaMultiDataConfig);
        }
    }

}
